using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using GSF.Objects;


namespace GSF
{

    public class SceneMgr : Microsoft.Xna.Framework.DrawableGameComponent
    {
        SpriteBatch m_spriteBatch;
        Terrains m_terrains;
        List<Enemy> m_enemies;
        List<Skill> m_skills;
        List<Tower> m_towers;
        CollisionMgr m_collisionMgr;

        Wave m_wave;
        EventMgr m_eventMgr;

        public SceneMgr(Game game)
            : base(game)
        {
            m_terrains = new Terrains(game);
            m_enemies = new List<Enemy>();
            m_skills = new List<Skill>();
            m_towers = new List<Tower>();
        }

        public override void Initialize()
        {
            // TODO: Add your initialization code here
            base.Initialize();
        }

        protected override void LoadContent()
        {
            m_spriteBatch = new SpriteBatch(GraphicsDevice);
            m_terrains.Init(Game);
            m_wave = new Wave(Game, 10, m_terrains);
            m_eventMgr = new EventMgr(Game, ResourceMgr.Instance.getEffect(0).path,
                ResourceMgr.Instance.getEffect(0).rows, ResourceMgr.Instance.getEffect(0).cols);
            CollisionMgr.Instance.Init(ref m_wave.m_enemies, ref m_towers);

            base.LoadContent();
        }

        public override void Update(GameTime gameTime)
        {
            // TODO: Add your update code here
            m_wave.Update(gameTime);
            m_eventMgr.Update();

            foreach (Enemy e in m_wave.Enemies)
            {

                e.Update(gameTime);
                foreach (Enemy e2 in m_wave.Enemies)
                {
                    if (e2 != e)
                        CollisionMgr.Instance.twoObjCollision(e, e2);
                    else
                        continue;
                }
            }
            
            base.Update(gameTime);
        }

        public override void Draw(GameTime gameTime)
        {
            m_spriteBatch.Begin();

            m_terrains.Draw(m_spriteBatch);
            foreach (Enemy e in m_wave.Enemies)
                e.Draw(m_spriteBatch);
            m_eventMgr.Draw(m_spriteBatch);

            m_spriteBatch.End();
            base.Draw(gameTime);
        }
    }
}
